<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>医生接诊页面</title>
    <style>

    </style>

</head>
<body>
<div id="app">

    <el-dialog title="挂号详情" :visible.sync="dialogSelcectFinishDiagnosis" width="50%">

        <el-form :model="diagnosis" >
            <el-form-item label="患者自述" :label-width="formLabelWidth">
                <el-input
                        type="textarea"
                        :autosize="{ minRows: 2, maxRows: 4}"
                        placeholder="请输入内容"
                        v-model="diagnosis.narration"
                        disabled>
                </el-input>
            </el-form-item>
            <el-form-item label="诊断结果" :label-width="formLabelWidth">
                <el-input
                        type="textarea"
                        :autosize="{ minRows: 2, maxRows: 4}"
                        placeholder="请输入内容"
                        v-model="diagnosis.diagnosisResult"
                        disabled>
                </el-input>
            </el-form-item>
            <el-table
                    :data="diagnosis.medicationList"
                    style="width: 100%">
                <el-table-column
                        prop="medicationName"
                        label="药品/服务名称">
                </el-table-column>
                <el-table-column
                        prop="charge"
                        label="收费">
                </el-table-column>
            </el-table>
            <br>
            <el-form-item label="总收费" :label-width="formLabelWidth">
                <el-input v-model="diagnosis.totalCharges" autocomplete="off" style="width: 15%" disabled></el-input>
            </el-form-item>

        </el-form>

    </el-dialog>



    <el-dialog title="接诊" :visible.sync="dialogAddDiagnosis" width="35%">
        <el-form :model="addDiagnosis" >
            <el-form-item label="患者自述" :label-width="formLabelWidth">
                <el-input
                        type="textarea"
                        :autosize="{ minRows: 2, maxRows: 4}"
                        placeholder="请输入内容"
                        v-model="addDiagnosis.narration">
                </el-input>
            </el-form-item>

            <el-form-item label="诊断结果" :label-width="formLabelWidth">
                <el-input
                        type="textarea"
                        :autosize="{ minRows: 2, maxRows: 4}"
                        placeholder="请输入内容"
                        v-model="addDiagnosis.diagnosisResult">
                </el-input>
            </el-form-item>

            <el-form-item label="开药" :label-width="formLabelWidth">

                <template>
                    <el-select
                            v-model="value"
                            multiple
                            filterable
                            remote
                            reserve-keyword
                            placeholder="请输入药品关键词"
                            :remote-method="remoteMethod"
                            :loading="loading">
                        <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </template>

            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogAddDiagnosis = false">取 消</el-button>
            <el-button type="primary" @click="AddDiagnosis(),dialogAddDiagnosis = false">确 定</el-button>
        </div>
    </el-dialog>


    <div>
        <h2>医生接诊页面</h2>
        <el-divider></el-divider>
    </div>
    <template>
        <el-tabs :tab-position="tabPosition" style="height: 600px;">

            <el-tab-pane label="今日待接诊单">
              <div>
                <el-form :inline="true" :model="selectReception" class="demo-form-inline">
                    <el-form-item label="患者姓名">
                      <el-input v-model="selectReception.patientName" placeholder="患者姓名"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" @click="getTodayReceptionList()">查询</el-button>
                    </el-form-item>
                </el-form>
                <el-table
                        :data="todayReceptionList"
                        style="width: 100%"
                        :row-class-name="tableRowClassName"
                        height="550px">
                  <el-table-column
                          prop="patientName"
                          label="患者姓名">
                  </el-table-column>
                  <el-table-column
                          prop="idCard"
                          label="患者身份证">
                  </el-table-column>
                  <el-table-column
                          prop="dateTime"
                          label="时间段">
                  </el-table-column>
                  <el-table-column label="操作" width="180">
                    <template slot-scope="scope">
                      <el-button
                              size="mini"
                              type="primary"
                              @click="getReceptionId(scope.$index, scope.row),dialogAddDiagnosis= true">接诊</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>

            </el-tab-pane>

            <el-tab-pane label="已接诊记录">
                <div>
                    <el-form :inline="true" :model="selectFinishReception" class="demo-form-inline">
                        <el-form-item label="患者姓名">
                            <el-input v-model="selectFinishReception.patientName" placeholder="患者姓名"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="getFinishReceptionList()">查询</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table
                            :data="finishReceptionList"
                            style="width: 100%"
                            :row-class-name="tableRowClassName"
                            height="550px">
                        <el-table-column
                                prop="patientName"
                                label="患者姓名">
                        </el-table-column>
                        <el-table-column
                                prop="idCard"
                                label="患者身份证">
                        </el-table-column>
                        <el-table-column
                                prop="dateTime"
                                label="时间段">
                        </el-table-column>
                        <el-table-column label="操作" width="180">
                            <template slot-scope="scope">
                                <el-button
                                        size="mini"
                                        type="primary"
                                        @click="getFinishDiagnosis(scope.$index, scope.row)">诊断结果详情</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </el-tab-pane>

        </el-tabs>
    </template>


</div>


<script src="js/vue.js"></script>
<script src="element-ui/lib/index.js"></script>
<link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">

<script src="js/axios-0.18.0.js"></script>

<script>
    const token = localStorage.getItem('token');
  new Vue({
    el: "#app",
    mounted() {
        this.getTodayReceptionList()
        this.getChooseMedication()
        this.getFinishReceptionList()
    },
    methods: {
        getFinishReceptionList(){
            var _this = this
            axios({
                method:"post",
                url:"/reception/getFinishReceptionByDoctorId",
                data:_this.selectFinishReception,
                headers: {
                    Authorization: `${token}`
                }
            }).then(function (resp) {
                if(resp.data.code == 20041){
                    _this.finishReceptionList = resp.data.data
                }else if(resp.data.code == 20050){
                    alert(resp.data.msg)
                    window.location.assign("hospitalLogin.html");
                }else{
                    alert("失败")
                }
            })
        },
        getFinishDiagnosis(index,row){
            var reception = {}
            reception.receptionId = row.receptionId
            var _this = this
            axios({
                method:"post",
                url:"/diagnosis/getDiagnosisByReceptionId",
                data:reception,
                headers: {
                    Authorization: `${token}`
                }
            }).then(function (resp) {
                if(resp.data.code == 20041){
                    _this.diagnosis = resp.data.data
                    _this.dialogSelcectFinishDiagnosis =true
                }else if(resp.data.code == 20050){
                    alert(resp.data.msg)
                    window.location.assign("hospitalLogin.html");
                }else if(resp.data.code == 20040){
                    alert("还未完成问诊")
                }
            })
        },
        getReceptionId(index,row){
            this.addDiagnosis.receptionId = row.receptionId
        },
        AddDiagnosis(){
            var _this = this
            this.addDiagnosis.medicationIds = this.value
            axios({
                method:"post",
                url:"/diagnosis/addDiagnosis",
                data:_this.addDiagnosis,
                headers: {
                    Authorization: `${token}`
                }
            }).then(function (resp) {
                if(resp.data.code == 20011){
                    _this.getTodayReceptionList()
                    _this.getFinishReceptionList()
                }else if(resp.data.code == 20050){
                    alert(resp.data.msg)
                    window.location.assign("hospitalLogin.html");
                }else if(resp.data.code == 20010){
                    alert("失败")
                }
            })
        },
        getChooseMedication(){
            var _this = this
            axios({
                method:"get",
                url:"/medication/getChooseMedication",
                headers: {
                    Authorization: `${token}`
                }
            }).then(function (resp) {
                if(resp.data.code == 20041){
                    _this.list = resp.data.data
                }else if(resp.data.code == 20050){
                    alert(resp.data.msg)
                    window.location.assign("hospitalLogin.html");
                }else{
                    alert("失败")
                }
            })
        },
        remoteMethod(query) {
            if (query !== '') {
                this.loading = true;
                setTimeout(() => {
                    this.loading = false;
                    this.options = this.list.filter(item => {
                        return item.label.toLowerCase()
                            .indexOf(query.toLowerCase()) > -1;
                    });
                }, 200);
            } else {
                this.options = [];
            }
        },
        getTodayReceptionList(){
            var _this = this
            axios({
                method:"post",
                url:"/reception/getTodayReceptionByDoctorId",
                data:_this.selectReception,
                headers: {
                    Authorization: `${token}`
                }
            }).then(function (resp) {
                if(resp.data.code == 20041){
                    _this.todayReceptionList = resp.data.data
                }else if(resp.data.code == 20050){
                    alert(resp.data.msg)
                    window.location.assign("hospitalLogin.html");
                }else{
                    alert("失败")
                }
            })
        },
        tableRowClassName({row, rowIndex}) {
            let rindex=rowIndex % 4;
            if (rindex === 1) {
                return 'warning-row';
            } else if (rindex === 3) {
                return 'success-row';
            }
            return '';
        },
    },
    data() {
          return {
              tabPosition: 'left',
              todayReceptionList:[],
              dialogAddDiagnosis: false,
              selectReception:{},
              doctor:{
                doctorId:'',
              },
              formLabelWidth: '120px',
              addDiagnosis:{
                  receptionId:'',
                  narration:'',
                  diagnosisResult:'',
                  medicationIds:[]
              },
              options: [],
              value: [],
              list: [],
              loading: false,
              finishReceptionList:[],
              diagnosis:{},
              selectFinishReception:{},
              dialogSelcectFinishDiagnosis: false,
          }

    }
  })

</script>
</body>
</html>